<?php

namespace App\Http\Controllers\Mobile;

use App\Models\Collect;

class CollectController extends BaseController
{

    public function index()
    {

        return $this->view('mobile.user.collect');
    }

    public function getJson()
    {
        $type = $this->request->get('type');
        $offset = $this->request->input('offset');
        $count  = $this->request->input('count');
        $offset = $offset ? $offset : 0;
        $count  = $count ? $count : 20;

        $items = Collect::where('datatype', $type)->where('uid', $this->uid)->offset($offset)->limit($count)
            ->orderByDesc('id')->get()->map(function ($item){
                $item->image = image_url($item->image);
                $item->created_at = @date('Y-m-d H:i:s', $item->created_at);
                if ($item->datatype == 'item'){
                    $item->url = mobile_item_url($item->dataid);
                } elseif ($item->datatype == 'shop'){
                    $item->url = mobile_shop_url($item->dataid);
                } else {
                    $item->url = mobile_post_url($item->dataid);
                }
                return $item;
            });

        return ajaxReturn(['items'=>$items]);
    }
}
